var app = getApp();
var int = (app.globalData.statusBarHeight * 2) + 20;
const skinBehavior = require("../../../utils/themeSkin/skinBehavior");
Page({

  behaviors: [skinBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: int,
    id: "",
    list: [],
    member: {},
    page: 1,
    total_page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.id || '';
  },
  back() {
    wx.navigateBack();
  },
  handle_edit() {
    wx.navigateTo({
      url: '/mircoApp/customer_file/edit/edit?id=' + this.data.member.id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData();
    this.getDetail();
  },
  getData(page = 1) {
    let json = {
      customer_archive_id: this.data.id,
      page
    }
    app._postNetWork({
      url: app.getNetAddresss("plugin.customer-archive.frontend.customer-archive.get-project-list"),
      data: json,
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (result) {
          let list = page == 1 ? data.data : this.data.list.concat(data.data);
          this.data.page = data.current_page;
          this.data.total_page = data.last_page;
          this.setData({
            list
          });
        } else {
          app.tips(msg);
        }
      }
    })
  },
  getDetail() {
    let json = {
      customer_archive_id: this.data.id
    };
    app._postNetWork({
      url: app.getNetAddresss("plugin.customer-archive.frontend.customer-archive.get-customer-info"),
      data: json,
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (result) {
          this.setData({
            member: data
          });
        } else {
          app.tips(msg);
        }
      }
    })

  },
  goto(e) {
    let {
      item = {}, type = ''
    } = e.currentTarget.dataset;
    if (type == 'add') {
      wx.navigateTo({
        url: '/mircoApp/customer_file/project/project?customer_archive_id=' + this.data.member.id,
      })
    } else {
      wx.navigateTo({
        url: '/mircoApp/customer_file/project/project?id=' + item.id,
      })

    }
  },
  getMoreData() {
    if (this.data.page >= this.data.total_page) return;
    let page = this.data.page + 1;
    this.getData(page);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getMoreData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})